﻿using System;
using System.IO;
using System.Web;

namespace SpiderMaster.AspNet.TradingSystem
{
    public partial class ImageManager
    {
        /// <summary> Gets the file path.
        /// </summary>
        /// <param name="ImageId">The image id.</param>
        /// <param name="ImageType">Type of the image.</param>
        /// <param name="ImageSize">Size of the image.</param>
        /// <param name="ForUrl">if set to <c>true</c> [for URL].</param>
        /// <returns></returns>
        [ReganSchroder(26, 10, 0, 0, 2009)]
        public static string GetFilePath(int ImageId, ImageType ImageType, ImageSize ImageSize, Boolean ForUrl)
        {
            string Result = null;
            string ImageSizeFileNameToken = GetImageSizeFileNameToken(ImageType, ImageSize);
            string ImageServerDirectory = GetImageServerDirectory(ImageType).TrimEnd(char.Parse("/"));

            switch (ImageType)
            {
                #region Category Browse

                case ImageType.CategoryBrowse:
                    // TEMPORARY OVER-RIDE // ##ERROR##
                    // ImageId = DefaultValues.IdNullValue;

                    if (ForUrl)
                        Result = String.Format("{0}/{1}/{2}.{3}.png", SystemManager.Current.GetSiteUrl().TrimEnd(char.Parse("/")), ImageServerDirectory, ImageId, ImageSizeFileNameToken);
                    else
                    {
                        HttpContext Context = HttpContext.Current;
                        if (Context != null)
                        {
                            String ServerDirectory = Context.Server.MapPath(ImageServerDirectory);
                            String File = String.Format("{0}.{1}.png", ImageId, ImageSizeFileNameToken);
                            Result = Path.Combine(ServerDirectory, File);
                        }
                    }
                    return Result;

                #endregion

                #region Location Browse

                case ImageType.LocationBrowse:
                    // TEMPORARY OVER-RIDE // ##ERROR##
                    ImageId = 0;

                    if (ForUrl)
                        Result = String.Format("{0}/{1}/{2}.{3}.png", SystemManager.Current.GetSiteUrl().TrimEnd(char.Parse("/")), ImageServerDirectory, ImageId, ImageSizeFileNameToken);
                    else
                    {
                        HttpContext Context = HttpContext.Current;
                        if (Context != null)
                        {
                            String ServerDirectory = Context.Server.MapPath(ImageServerDirectory);
                            String File = String.Format("{0}.{1}.png", ImageId, ImageSizeFileNameToken);
                            Result = Path.Combine(ServerDirectory, File);
                        }
                    }
                    return Result;

                #endregion

                #region Reserve Flag

                case ImageType.ReserveFlag:
                    if (ForUrl)
                        Result = String.Format("{0}/{1}/{2}.{3}.png", SystemManager.Current.GetSiteUrl().TrimEnd(char.Parse("/")), ImageServerDirectory, ImageId, ImageSizeFileNameToken);
                    else
                    {
                        HttpContext Context = HttpContext.Current;
                        if (Context != null)
                        {
                            string ServerDirectory = Context.Server.MapPath(ImageServerDirectory);
                            string File = String.Format("{0}.{1}.png", ImageId, ImageSizeFileNameToken);
                            Result = Path.Combine(ServerDirectory, File);
                        }
                    }
                    return Result;

                #endregion

                default:
                    return Result;
            }
        }
    }
}